package com.framework.modules.chat.service.impl;

import com.framework.modules.dataview.entity.StatLikeAndAttentUserEntity;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.Query;

import com.framework.modules.chat.dao.ChatFriendDao;
import com.framework.modules.chat.entity.ChatFriendEntity;
import com.framework.modules.chat.service.ChatFriendService;


@Service("chatFriendService")
public class ChatFriendServiceImpl extends ServiceImpl<ChatFriendDao, ChatFriendEntity> implements ChatFriendService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<ChatFriendEntity> page = this.selectPage(
                new Query<ChatFriendEntity>(params).getPage(),
                new EntityWrapper<ChatFriendEntity>()
        );

        return new PageUtils(page);
    }

    public Integer updateFriendBlockMessage(Integer to_uid,Integer from_uid,String block_message){
        return baseMapper.updateFriendBlockMessage(to_uid,from_uid,block_message);
    }

    @Override
    public Integer saveOrUpdateBatch(List<ChatFriendEntity> entityList) {
        return baseMapper.saveOrUpdateBatch(entityList);
    }
    @Override
    public Integer updateFriendState(Integer uid,Integer targetUid,Integer state){
        return baseMapper.updateFriendState(uid,targetUid,state);
    }

    @Override
    public StatLikeAndAttentUserEntity statLikeAndAttent(Integer uid) {
        return this.baseMapper.statLikeAndAttent(uid);
    }

    @Override
    public Map<String, Boolean> getIsAttentUserAndLikeUser(Integer uid, Integer targetUid) {
        Map<String,Boolean> result=new HashMap<>();
        result.put("isAttent",false);
        result.put("isLike",false);
        ChatFriendEntity chatFriendEntity=this.baseMapper.findById(uid,targetUid);
        if(null!=chatFriendEntity){
            int state=chatFriendEntity.getState();
            int isLike=chatFriendEntity.getIsLiked();
            if(state==1){
                result.put("isAttent",true);
            }
            if(isLike==1){
                result.put("isLike",true);
            }
        }
        return result;
    }


}
